home *** CD-ROM | disk | FTP | other *** search
- #include "FontMancer.h"
- #include "FontDisplay.h"
- #include "Standard.h"
-
- extern WindowPtr gMainWindow;
- extern Str255 gSamplePhrase;
-
- void FindPlaceInList(Point *testCell, Str255 resName, FMStuff *FMStore)
- {
-
- Str255 testName;
- short testLen = 255;
-
- SetPt(testCell,0,0);
- if ((**FMStore->fontList).dataBounds.bottom == 0) return;
- LGetCell(&testName[1], &testLen,*testCell,FMStore->fontList);
- testName[0] = testLen;
- while ((RelString(resName,testName,FALSE,TRUE) >= 0)) {
- if (LNextCell(FALSE,TRUE,testCell,FMStore->fontList))
- {
- testLen = 255;
- LGetCell(&testName[1],(short *) &testLen,*testCell,FMStore->fontList);
- testName[0] = testLen;
- }
- else
- break;
- }
- }
-
- void LoadFontInfo(FMStuff *FMStore)
- {
- int loop;
- //int index = 0;
- //short resID, checkChar, listLimit = 0;
- int listLimit = 0;
- Str255 tempStr = "\p";
- Handle resHandle;
- //ResType Type;
- Point cell;
- CursHandle hWatchCursor;
- MenuHandle tempFontMenu;
-
- hWatchCursor = GetCursor(watchCursor);
- HLock((Handle) hWatchCursor);
- SetCursor(*hWatchCursor);
- tempFontMenu = NewMenu(300,tempStr);
- AddResMenu(tempFontMenu,'FONT');
- FMStore->numFonts = CountMItems(tempFontMenu);
- for (loop = 1; loop <= FMStore->numFonts; loop++) {
- GetItem(tempFontMenu,loop,tempStr);
- listLimit += tempStr[0];
- if (listLimit < 32000) {
- SetPt(&cell,0,loop - 1);
- //FindPlaceInList(&cell,tempStr,FMStore);
- LAddRow(1,cell.v,FMStore->fontList);
- LSetCell(&(tempStr[1]),tempStr[0],cell,FMStore->fontList);
- }
- else {
- loop = FMStore->numFonts;
- InfoAlert(infoLimitReached,NIL);
- }
- }
- DisposeMenu(tempFontMenu);
- /*for (loop = 1; loop <= FMStore->numFonts; loop++) {
- resHandle = GetIndResource('FOND',loop);
- GetResInfo(resHandle,&resID,&Type,resName);
- checkChar = resName[1];
- if ((checkChar >= 'a' && checkChar <= 'z') ||
- (checkChar >='A' && checkChar <='Z')) {
- listLimit += resName[0];
- if (listLimit < 32000) {
- SetPt(&cell,0,loop - 1);
- FindPlaceInList(&cell,resName,FMStore);
- LAddRow(1,cell.v,FMStore->fontList);
- LSetCell(&(resName[1]),resName[0],cell,FMStore->fontList);
- }
- else {
- loop = FMStore->numFonts;
- InfoAlert(infoLimitReached,NIL);
- }
- }
- ReleaseResource(resHandle);
- }*/
-
- HUnlock((Handle) hWatchCursor);
- SetCursor(&qd.arrow);
- ReleaseResource((Handle) hWatchCursor);
- }
-
- void InitFontListVars(FMStuff *FMStore)
- {
- //FMStore->numFonts = CountResources('FOND');
- FMStore->fontStyle = FMStore->fontDisplayed = 0;
- FMStore->fontSize = 2;
- }
-
- void SetDisplayFont(Point selectedCell, FMStuff *FMStore)
- {
- short cellDataLen;
- Str255 cellData;
-
- cellDataLen = 255;
- LGetCell(&cellData[1],&cellDataLen,selectedCell,FMStore->fontList);
- cellData[0] = cellDataLen;
- GetFNum(cellData,&FMStore->fontDisplayed);
- }
-
- void CreateFontList()
- {
- Rect dataBounds,itemRect;
- Point cellSize;
- FMStuff *FMStore;
-
- FMStore = (FMStuff *) GetWRefCon(gMainWindow);
- InitFontListVars(FMStore);
- SetPt(&cellSize,0,0);
- SetRect(&dataBounds,0,0,1,0);
- SetRect(&itemRect,FMStore->itemRects[iListRect].left,FMStore->itemRects[iListRect].top,
- FMStore->itemRects[iListRect].right,FMStore->itemRects[iListRect].bottom);
- itemRect.right -= 15; //pull it in so as not to kill the vertical scroll bar
- FMStore->fontList = LNew(&itemRect,&dataBounds,cellSize,0,gMainWindow,
- FALSE,FALSE,FALSE,TRUE);
- HLock((Handle)FMStore->fontList);
- (**FMStore->fontList).selFlags = lOnlyOne | lNoNilHilite;
- LoadFontInfo(FMStore);
- SetPt(&cellSize,0,0);
- LSetSelect(TRUE,cellSize,FMStore->fontList);
- SetDisplayFont(cellSize,FMStore);
- LDoDraw(TRUE,FMStore->fontList);
- HUnlock((Handle)FMStore->fontList);
- }
-
- void DisposeFontList()
- {
- FMStuff *FMStore;
-
- FMStore = (FMStuff *) GetWRefCon(gMainWindow);
- LDispose(FMStore->fontList);
- DisposePtr((Ptr) FMStore);
- }
-
- void DrawBorder(Rect borderRect)
- {
- PenState savethePen;
-
- GetPenState(&savethePen);
- PenSize(1,1);
- InsetRect(&borderRect,-1,-1);
- FrameRect(&borderRect);
- SetPenState(&savethePen);
- }
-
- void UpdateFontList(WindowPtr theWin)
- {
- FMStuff *FMStore;
-
- FMStore = (FMStuff *) GetWRefCon(theWin);
- HLock((Handle)FMStore->fontList);
- LUpdate(theWin->visRgn,FMStore->fontList);
- DrawBorder((**FMStore->fontList).rView);
- HUnlock((Handle)FMStore->fontList);
- }
-
- void HandleListSelect(EventRecord *event)
- {
- Point mouseLoc, selectedCell;
- FMStuff *FMStore;
- short ignored;
- ListHandle theList;
-
- SetPt(&mouseLoc,event->where.h,event->where.v);
- GlobalToLocal(&mouseLoc);
- FMStore = (FMStuff *) GetWRefCon(gMainWindow);
- theList = FMStore->fontList;
- HLock((Handle) theList);
- ignored = LClick(mouseLoc,event->modifiers,theList);
- SetPt(&selectedCell,0,0);
- if (LGetSelect(TRUE,&selectedCell,theList)) {
- SetDisplayFont(selectedCell,FMStore);
- UpdateSampleRect(FMStore);
- }
- HUnlock((Handle) theList);
- }